<template>
  <div style="width: 100%">
    <div id="deawer">
      <v-tableTitle
        :btnConfig="btnConfig"
        @cancel="cancel"
        @shipping="shipping"
      ></v-tableTitle>
      <div class="detailBox">
        <v-detail ref="detail"></v-detail>
      </div>
      <div class="detailListBox">
        <v-detailList ref="detailList"></v-detailList>
      </div>
    </div>
  </div>

</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import skipMixin from "@/mixins/SkipMixin";
import tableTitle from "commons/TableTitle";
import detail from "../details/Detail"
import detailList from "../detailsList/DetailList"

export default {
  name: "",
  mixins: [baseMixin, skipMixin],
  data () {
    return {
      newFlag: false,
      routeData: {},
      orderData:[]
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('out.shipping'), certigier: !this.btnPermNameList.includes('WM05020802'), invalid: "shipping" },
        { label: this.$t('common.return'), certigier: !this.btnPermNameList.includes('WM05020803'), invalid: "cancel" },
      ]
    }
  },
  created () {
  },
  methods: {
    //发运按钮

    shipping () {
      let data = this.orderData;
      if(data.length <1){
        this.$message.error(this.$t('msg.msg16'));
        return;
      }
      data.forEach(async (item, index) => {
        try {
          let res = await this.$api.get(`/ordersDeliverAll/${item.orderkey}`);
          
            this.$message.success(res.returnMgr);
            this.cancel();
          
        } catch (e) {
          this.$message.error(e);
        }
      });
    },
    //弹框取消
    cancel () {
      let routerName = JSON.parse(sessionStorage.getItem('routerName'));
      let num = -1;
      if (routerName) {
        num = routerName.indexOf("waveship");
      }
      if (num === -1) {
        this.$router.push({ name: "waveship" });
      } else {
        num = num - 0;
        routerName.splice(num, 1);
        sessionStorage.setItem('routerName', JSON.stringify(routerName));
        this.$router.push({ name: "home1" })
      }

    },
  },
  mounted () {
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.routeData = data.routeData;
      this.newFlag = data.newFlag;
    } else {
      this.routeData = this.$store.state.routeData;
      this.newFlag = this.$store.state.newFlag;
    }

  },
  watch: {},
  components: {
    "v-tableTitle": tableTitle,
    "v-detail": detail,
    "v-detailList": detailList,
  },
  beforeDestroy () {
    let routerName = JSON.parse(sessionStorage.getItem('routerName'));
    let num = -1;
    if (routerName) {
      num = routerName.indexOf("waveship");
    }
    if (num === -1) {
    } else {
      num = num - 0;
      routerName.splice(num, 1);
      sessionStorage.setItem('routerName', JSON.stringify(routerName));
    }
  }
}
</script>

<style scoped>
</style>
